/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Phan1.LietKe.QuayLui;

/**
 *
 * @author Giaotk
 */
public class PhanTichSo {

    int n;
    int[] x = new int[100];
    int[] t = new int[100];
    StringBuilder result = new StringBuilder();

    public PhanTichSo(int n) {
        this.n = n;
        x[0] = 1;
        t[0] = 0;
        Process(1);
        System.out.println(result);
    }

    public void Process(int i) {
        for (int j = x[i - 1]; j <= (n - t[i - 1]) / 2; j++) {
            x[i] = j;
            t[i] = j + t[i - 1];
            Process(i + 1);
            
        }
        x[i] = n - t[i - 1];
        PrintResult(i);
    }

    public void PrintResult(int k) {
        result.append(n).append(" = ");
        for (int i = 1; i < k; i++) {
            result.append(x[i]).append(" + ");
        }
        result.append(x[k]);
        result.append("\n");
    }
}
